﻿using System;
using System.Text;
using mfRCF.Core;
using mfRCF.Core.Extensions;
using mfRCF.Rss;
using Microsoft.SPOT;
using mfXmlSerializer;
using Microsoft.SPOT.Hardware;

namespace mfRCF.NetduinoPlus2.TestApp
{
    public class DatePostCommand : mfRcfCommand
    {
        public DatePostCommand(string httpPath)
            : base(httpPath, new mfPOSTMethod()) 
        {}

        public override void ExecuteCommand(mfIHttpContext httpContext)
        {
            var requestString = httpContext.Request.InputStream.ReadAllText();

            Debug.Print(GetType() + " received: " + requestString);

            //referenced from mfXmlSerializer
            var newDateTime = requestString.ConvertToDateTime();

            Utility.SetLocalTime(newDateTime);

            //write response
            httpContext.Response.StatusCode = enumHttpStatusCode.OK;
            httpContext.Response.Close();

            Debug.Print(GetType() + " executed, " + Debug.GC(false) + " bytes free, new datetime is: " + DateTime.Now);

        }
    }
}
